package com.qs.questionnairesurveysystem.mapper;

import com.qs.questionnairesurveysystem.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("INSERT INTO user (email, machineCode, username, phone, gender, birth, region, job, points, password) " +
            "VALUES (#{email}, #{machineCode}, #{username}, #{phone}, #{gender}, #{birth}, #{region}, #{job}, #{points}, #{password})")
    int insertUser(User user);

    @Update("UPDATE user SET email = #{email}, machineCode = #{machineCode}, username = #{username}, phone = #{phone}, " +
            "gender = #{gender}, birth = #{birth}, region = #{region}, job = #{job}, points = #{points}, password = #{password} " +
            "WHERE userId = #{userId}")
    int updateUser(User user);

    @Delete("DELETE FROM user WHERE userId = #{userId}")
    int deleteUser(Long userId);

    @Select("SELECT * FROM user WHERE userId = #{userId}")
    User findById(Long userId);

    @Select("SELECT * FROM user")
    List<User> findAll();

    @Select("SELECT * FROM user WHERE username = #{username}")
    User getUserByUsername(String username);
}
